def cut_array_front_back(array, key):
    """ 安全截取 前2,后3 共5个元素"""
    if key not in array:
        return []
    idx = array.index(key)
    length = len(array)
    start_idx = max(0, idx - 2)
    end_idx = min(length - 1, idx + 3)
    return array[start_idx:end_idx]


# 截取前,后5个元素
if __name__ == "__main__":
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    for i in a:
        data = cut_array_front_back(a, i)
        print(data)
    data = cut_array_front_back(a, 11)
    print(data)
